﻿Public Class ValidateEmail
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim oMember As New NENAData.NENAMember.NENAMember
        Dim oMembers = oMember.GetAllMembersAndApplicants()


        For Each iteration As NENAData.LINQ.Member In oMembers

            Dim strRegEx As String
            'strRegEx = "\b[A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b" 'checks for multiple .'s
            'below is possibley the RFC 2822 standard
            'old regex from disclaimer '^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$
            'http://www.regular-expressions.info/email.html
            'strRegEx = "(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"
            strRegEx = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.(?:[A-Z]{2}|com|ca|net|org|edu)$" 'good


            Dim m As Match = Regex.Match(iteration.EmailAddress, strRegEx, RegexOptions.IgnoreCase)


            If m.Success = False Then
                Response.Write("memberid " + iteration.Member_ID.ToString + ", firstname: " + iteration.FirstName + ", lastname " + iteration.LastName + ", email " + iteration.EmailAddress + "<br />")
            End If
        Next

    End Sub
End Class